package com.linkoog.devtools.intellij.ui.file_browse;

import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComponentWithBrowseButton;
import com.intellij.openapi.ui.TextComponentAccessor;
import com.intellij.openapi.util.NlsContexts;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class BrowseFolderActionListener<T extends JComponent> extends BrowseFolderRunnable<T> implements ActionListener {
    public BrowseFolderActionListener(
            @Nullable ComponentWithBrowseButton<T> textField,
            @Nullable Project project,
            FileChooserDescriptor fileChooserDescriptor,
            TextComponentAccessor<? super T> accessor) {
        super(project, fileChooserDescriptor, textField != null ? textField.getChildComponent() : null, accessor);
    }

    public BrowseFolderActionListener(@Nullable @NlsContexts.DialogTitle String title,
                                      @Nullable @NlsContexts.Label String description,
                                      @Nullable ComponentWithBrowseButton<T> textField,
                                      @Nullable Project project,
                                      FileChooserDescriptor fileChooserDescriptor,
                                      TextComponentAccessor<? super T> accessor) {
        super(title, description, project, fileChooserDescriptor, textField != null ? textField.getChildComponent() : null, accessor);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        run();
    }
}
